package com.study.cacheManager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.study.constant.CacheConstant;
import com.study.dao.entity.TLink;
import com.study.dao.mapper.TLinkMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author canace
 * @version 1.0
 * @description 短链接缓存管理器
 * @date 2024/1/31 12:58
 */

@Component
@RequiredArgsConstructor
public class LinkCacheManager {

    private final TLinkMapper linkMapper;

    @Cacheable(cacheManager = CacheConstant.REDIS_CACHE_MANAGER, cacheNames = CacheConstant.LINK_COUNT_BY_GID_CACHE_NAME)
    public List<Map<String, Object>> getShortLinkCountByGidS(List<String> requestParam) {
        QueryWrapper<TLink> queryWrapper = Wrappers.query(new TLink())
                .select("gid as gid, count(*) as shortLinkCount")
                .in("gid", requestParam)
                .eq("enable_status", 0)
                .eq("del_flag", 0)
                .groupBy("gid");
        return linkMapper.selectMaps(queryWrapper);
    }
}
